
function getImage(url, callback){
    let img = new Image();
    img.src = url;
    if(img.complete){
        callback(img.width, img.height);
    }else{
        img.onload = function(){
            callback(img.width, img.height);
        }
    }
}

function showBigImage(url) {
    getImage(url, function(w, h){
        let widht = $(window).width() * 0.7;
        let height = $(window).height() * 0.7;
        if (w > h) {
            widht = widht > w ? w : widht;
            height = widht * h/w;
        } else {
            height = height > h ? h : height;
            widht = height * w/h;
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shadeClose: true,
            area: [widht + 'px', height + 'px'],
            content: '<img src="' + url + '" οnclick="window.open(this.src)" style="max-width: ' + widht + 'px;max-height: ' + height + 'px;cursor:pointer;"/>'
        });
    });
}

// 使用
$(document).on('click', "table img,form img", function () {
    showBigImage($(this).attr("src"));
});

function search() {
    var keyword=$("#searchOem").val()
    window.location.href = "http://" + window.location.host + "/page/search?foundString=" + keyword;
}

function searchModel() {
    var keyword=$("#searchModel").val()
    var catalogId=$("#searchType").val()
    window.location.href = "http://" + window.location.host + "/page/model?keyWord=" + keyword + "&catalogId=" + catalogId;
}

window.onload = function () {
    //解析网址,获取catalogId keyWord foundString
    var param = location.search;			//search获得地址中的参数，内容为'?itemId=12'
    var result = param.match(/[^\?&]*=[^&]*/g); 	//match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
    param = {};					//让paras变成没有内容的json对象
    for(i in result){
        var temp = result[i].split('=');	//split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
        param[temp[0]] = temp[1];
    }
    oemSearch = document.getElementById("searchOem")
    console.log(param.foundString)
    oemSearch.value = param.foundString ? decodeURIComponent(param.foundString) : '';
    oemSearch.onkeydown = function (e) {
        var keyCode = e.keyCode || e.which;
        if (keyCode == '13') {
            search()
        }
    }
    modelSearch = document.getElementById("searchModel")
    modelSearch.value = param.keyWord ? decodeURIComponent(param.keyWord) : '';
    modelSearch.onkeydown = function (e) {
        var keyCode = e.keyCode || e.which;
        if (keyCode == '13') {
            searchModel()
        }
    }
    typeSearch = document.getElementById("searchType")
    typeSearch.value = param.catalogId ? param.catalogId : 0;
    typeSearch.onchange = function (e) {
        console.log('11')
        searchModel()
    }
}


